#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project ：turbo
@File    ：crypto_aes.py
@Author  ：赵加响
@Date    ：2024/9/20 14:08 
@Desc    ：
"""

from django.core.management.base import BaseCommand

from utils.crypto.handler import AESCryptoHandler


class Command(BaseCommand):
    help = 'Encrypt password with AES'
    requires_system_checks = False

    def add_arguments(self, parser):
        parser.add_argument('--password', type=str, help='Password that needs to be encrypted.')

    def handle(self, *args, **options):
        password = options['password']

        if password:
            crypto = AESCryptoHandler()
            encrypted_password = crypto.encrypt(password)
            if encrypted_password:
                self.stdout.write(self.style.SUCCESS('Generate crypto AES password successful.'))
                self.stdout.write(encrypted_password)
            else:
                self.stdout.write(
                    self.style.ERROR('Generate crypto AES password failed, please generate a key file first.'))
        else:
            self.stdout.write(self.style.ERROR('Please enter password(--password=123456).'))
